import { Body, Controller, Get, Post, Res, HttpStatus, UploadedFile, UseInterceptors, HttpException, Query,Request } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import request from 'request'
import {join, resolve} from 'path'
import { createWriteStream } from 'fs';
import { ValidTokenInterceptor } from '../../interceptor/validToken'
import { apibefore } from '../../router'
import { Treasury } from './treasury.entity';
import { TreasuryService } from './treasury.service';

@Controller(apibefore('/treasury'))
export class TreasuryController {
  constructor(private readonly service: TreasuryService) {}

  @Post('save')
  async save(@Body() data,@Request() req){
    let tr = await this.service.find_By_Platform(data.platform)
    if(!tr){
      tr = new Treasury()
    }
    tr.platform = data.platform
    tr.balance = data.balance || 0
    tr.update_time = new Date()
    return await this.service.save(tr)
  }

  @Get('find_by_platform')
  async find_by_platform(@Query() params){
    return await this.service.find_By_Platform(params.platform)
  }
}
